package org.teamswift.crow.rbac.repository;

import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.teamswift.crow.rbac.entity.CrowUser;
import org.teamswift.crow.rest.provider.jpa.ICrowRepositoryJpa;

import java.util.Collection;
import java.util.List;
import java.util.Optional;

@Repository
public interface CrowUserRepository extends ICrowRepositoryJpa<Integer, CrowUser> {

    Optional<CrowUser> findByUsername(String username);

    Optional<CrowUser> findByMobile(String mobile);

    Optional<CrowUser> findByMobileOrUsername(String mobile, String username);

    List<CrowUser> findAllByMobileIn(Collection<String> mobiles);

    @Query(value = "select * from crow_user where mobile = ?1", nativeQuery = true)
    Optional<CrowUser> getByMobileInAllOrganizations(String mobile);

}
